<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="会员账号、会员名称" clearable></el-input>
      </el-form-item>
      <el-form-item label="会员类型">
				<el-select v-model="dataForm.getUserType" placeholder="会员类型">
					<el-option label="全部" value="" ></el-option>
					<el-option label="普通联盟店" value="2" ></el-option>
					<el-option label="中级版联盟店" value="5" ></el-option>
          <el-option label="高级版联盟店" value="6" ></el-option>
					<el-option label="城市合伙人联盟店" value="8" ></el-option>
				</el-select>
			</el-form-item>
      <el-form-item label="审核状态">
				<el-select v-model="dataForm.status" placeholder="审核状态">
					<el-option label="全部" value="" ></el-option>
					<el-option label="待审核" value="0" ></el-option>
					<el-option label="审核通过" value="1" ></el-option>
          <el-option label="审核不通过" value="2" ></el-option>
					<el-option label="资料待完善" value="3" ></el-option>
          <el-option label="被锁定" value="5" ></el-option>
					<el-option label="注册了但未登陆" value="7" ></el-option>
				</el-select>
			</el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button @click="
          dataForm.keywords = ''
          dataForm.getUserType = ''
          dataForm.status = ''
          getDataList()">重置</el-button>
        <el-badge :value="this.num" class="item">
          <el-button size="small" @click="unaudited()">未审核</el-button>
          </el-badge>
          <el-form-item label="" style="margin-left:50px">
				<el-select v-model="dataForm.batch" placeholder="批量审核">
					<el-option label="审核通过" value="1" ></el-option>
          <el-option label="审核不通过" value="2" ></el-option>
				</el-select>
        <el-button v-if="isAuth('user:business:modifyBatchByIds')" type="danger" @click="batch()" :disabled="dataListSelections.length <= 0">批量审核</el-button>
			</el-form-item>
        <!-- <el-button v-if="isAuth('business:shoppinguser:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button> -->
        <el-button v-if="isAuth('user:business:removeBatchByIds')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      stripe
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>

      <el-table-column
        prop="path"
        header-align="center"
        align="center"
        label="图片"
        width="300px">
        <template slot-scope="scope">
          <div>
            <el-popover
              placement="right"
              title=""
              trigger="hover">
                <img class="image1" :src="'http://image.yilianbaihui.cn/consumer/'+ scope.row.path"/>
                <img slot="reference" :src="'http://image.yilianbaihui.cn/consumer/' + scope.row.path " style="height: 60px;width: 60px; border-radius:200px;margin-top: 10px">
            </el-popover>
            <ul class="jx_ul-info-list">
              <li style="list-style-type:none;"><label v-if="scope.row.ww != null">店铺名称：</label>{{scope.row.trueName}}</li>
              <li style="list-style-type:none;"><label>电话：</label>{{scope.row.mobile}}</li>
            </ul>
          </div>
        </template>
      </el-table-column>
      <!--<el-table-column
        prop="mobile"
        header-align="center"
        align="center"
        label="电话">
      </el-table-column>
      <el-table-column
        prop="trueName"
        header-align="center"
        align="center"
        label="会员名称">
      </el-table-column>-->

      <el-table-column
        prop="username"
        header-align="center"
        align="center"
        label="会员账号">
      </el-table-column>
      <el-table-column
        prop="realName"
        header-align="center"
        align="center"
        label="会员负责人">
      </el-table-column>
      <el-table-column
        prop="userType"
        header-align="center"
        align="center"
        label="会员类型">
          <template slot-scope="scope">
            <p v-if="scope.row.userType == 1"> 区域运营商</p>
            <p v-else-if ="scope.row.userType == 2">普通联盟店</p>
            <p v-else-if ="scope.row.userType == 3">消费者</p>
            <p v-else-if ="scope.row.userType == 4">VIP会员</p>
            <p v-else-if ="scope.row.userType == 5">中级版联盟店</p>
            <p v-else-if ="scope.row.userType == 6">高级版联盟店</p>
            <p v-else-if ="scope.row.userType == 7">城市合伙人</p>
            <p v-else-if ="scope.row.userType == 8">城市合伙人联盟店</p>
          </template>
      </el-table-column>
      <el-table-column
        prop="paNUserName"
        header-align="center"
        align="center"
        label="上级名称">
      </el-table-column>
      <el-table-column
        prop="paNUserTrueName"
        header-align="center"
        align="center"
        label="上级账号">
      </el-table-column>
      <el-table-column
        prop="paNUserType"
        header-align="center"
        align="center"
        label="上级类型">
          <template slot-scope="scope">
            <p v-if="scope.row.paNUserType == 1"> 区域运营商</p>
            <p v-else-if ="scope.row.paNUserType == 2">普通联盟店</p>
            <p v-else-if ="scope.row.paNUserType == 3">消费者</p>
            <p v-else-if ="scope.row.paNUserType == 4">VIP会员</p>
            <p v-else-if ="scope.row.paNUserType == 5">中级版联盟店</p>
            <p v-else-if ="scope.row.paNUserType == 6">高级版联盟店</p>
            <p v-else-if ="scope.row.paNUserType == 7">城市合伙人</p>
            <p v-else-if ="scope.row.paNUserType == 8">城市合伙人联盟店</p>
          </template>
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        align="center"
        label="审核状态">
        <template slot-scope="scope">
                <p v-if="scope.row.status == 0">未审核</p>
                <p v-if="scope.row.status == 1" style="color: green">审核通过</p>
                <p v-if="scope.row.status == 2" style="color: red">审核不通过</p>
                <p v-if="scope.row.status == 3">资料待完善</p>
                <p v-if="scope.row.status == 5" style="color: red">被锁定</p>
                <p v-if="scope.row.status == 7">注册了但未登陆</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="payFullSend"
        header-align="center"
        align="center"
        label="满送类型">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.payFullSend == '100-50'" type="warning"><span style="color: #000000">消费100送50</span></el-tag>
          <el-tag v-if="scope.row.payFullSend == '100-100'" type="warning"><span style="color: #000000">消费100送100</span></el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="addTime"
        header-align="center"
        align="center"
        label="注册时间">
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        align="center"
        label="会员状态">
        <template slot-scope="scope">
            <div>
                <el-button size="small" style="background: #6CDDD1; width: 50px; color:#000000"  @click="handleAdopt(scope.row.id)" v-if="(scope.row.status)== 0">通过</el-button><br/>
                <el-button size="small" style="background: #F56C6C; width: 50px;margin-top: 5px; color:#000000"  @click="handleNoAdopt(scope.row.id)" v-if="(scope.row.status)== 0">拒绝</el-button>
                <!-- <p v-if="scope.row.status == 1">审核通过</p>
                <p v-if="scope.row.status == 2">审核不通过</p>
                <p v-if="scope.row.status == 3">资料待完善</p>
                <p v-if="scope.row.status == 5">被锁定</p>
                <p v-if="scope.row.status == 7">注册了但未登陆</p> -->
                <el-button size="small" style="background: #EBB563; width: 77px; color:#000000; margin-bottom: 30px; text-align: center" icon="check" @click="reExamination(scope.row.id)" v-if="(scope.row.status) !== 0">重新审核</el-button>
            </div>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" style="color:#000000" size="small" @click="addOrUpdateHandle(scope.row.id)">查看</el-button>
          <el-button type="text" style="color:#000000" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
          <el-button style="background: #6CDDD1; color:#000000" size="small" @click="deleteHandle1(scope.row.id, scope.row.payFullSend)">修改满送</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <re-examination v-if="addOrUpdateVisible" ref="reExamination" @refreshDataList="getDataList"></re-examination>
    <update-full-delivery v-if="addOrUpdateVisible" ref="updateFullDelivery" @refreshDataList="getDataList"></update-full-delivery>
  </div>
</template>

<script>
  import AddOrUpdate from './shoppinguser-add-or-update'
  import reExamination from './re-examination'
  import updateFullDelivery from './update-full-delivery'
  export default {
    data () {
      return {
        dataForm: {
          keywords: '',
          getUserType: '',
          status: '',
          batch: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        checkComment: '',
        num: ''
      }
    },
    components: {
      AddOrUpdate,
      reExamination,
      updateFullDelivery
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/user/business/queryBusinessList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'getUserType': this.dataForm.getUserType,
            'status': this.dataForm.status
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
        // 未审核数量
        this.$http({
          url: this.$http.adornUrl('/user/business/queryCount'),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.num = data.data
          } else {
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
        console.log(val)
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 修改满送
      deleteHandle1 (id, payFullSend) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.updateFullDelivery.init(id, payFullSend)
        })
      },
      reExamination (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.reExamination.init(id)
        })
      },
      // 批量审核
      batch (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        if (this.dataForm.batch === '') {
          this.$message('请选择审核类型')
          return false
        }
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '审核' : '批量审核'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl(`/user/business/modifyBatchByIds/${this.dataForm.batch}`),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 批量删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/user/business/removeBatchByIds'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 未审核的联盟店
      unaudited () {
        this.dataForm.status = 0
        this.getDataList()
      },
      // 通过审核
      handleAdopt (id) {
        this.$confirm(`确定对该用户进行审核通过操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/user/business/modifyStatusById'),
            method: 'post',
            data: this.$http.adornData(id, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
              this.getDataList()
            }
          })
        })
      },
      // 不通过审核
      handleNoAdopt (id) {
        this.$prompt('请输入不通过原因', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(({value}) => {
          var noAdopts = {'id': id, 'checkComment': value}
          this.$http({
            url: this.$http.adornUrl('/user/business/modifyStatusByIds'),
            method: 'post',
            data: this.$http.adornData(noAdopts, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
              this.getDataList()
            }
          })
        })
      }
    }
  }
</script>

<style>
  .image1{
    width:450px;
    height:300px;
    margin-top: 10px;
    float: left;
  }
  .jx_ul-info-list ul {
    margin:0;
    padding:0;
    float: left;
  }
  .jx_ul-info-list li label {
    display: inline-block;
    text-align: left;
    vertical-align: top;
  }
  .jx_ul-info-list {
    margin:0;
    padding:0;
    margin-left: 30px;
    margin-top: 20px;
    float: right;
  }
  .jx_ul-info-list li {
    text-align: left;
    width: 180px;
  }
</style>
